#include <stack>
#include <string>
#include <iostream>
using namespace std;
class Solution
{
public:
    int priority(char c)
    {
        switch (c)
        {
        case '#':
            return 0;
        case '+':
            return 1;
        case '-':
            return 2;
        case '*':
            return 3;
        case '/':
            return 3;
        }
        return -1;
    }
    void compute(stack<int> &operand, stack<char> &op)
    {
        char opc = op.top();
        op.pop();
        if (opc == '#')
        {
            return;
        }
        if (operand.size() > 1)
        {
            int b = operand.top();
            operand.pop();
            int a = operand.top();
            operand.pop();
            switch (opc)
            {
            case '+':
                operand.push(a + b);
                break;
            case '-':
                operand.push(a - b);
                break;
            case '*':
                operand.push(a * b);
                break;
            case '/':
                operand.push(a / b);
                break;
            }
        }
    }

    int calculate(string s)
    {
        int ans = 0;
        s = '#' + s + "#";
        stack<int> operandStack;
        stack<char> operatorStack;
        int num = 0;
        for (char c : s)
        {
            if (c == ' ')
            {
                continue;
            }
            else if (isdigit(c))
            {
                num = num * 10 + (c - '0');
            }
            else
            {
                if (c == '#' && operatorStack.empty())
                {
                    operatorStack.push(c);
                    continue;
                }
                operandStack.push(num);

                while (!operatorStack.empty() && priority(operatorStack.top()) >= priority(c))
                {
                    compute(operandStack, operatorStack);
                }

                operatorStack.push(c);
                num = 0;
            }
        }
        while (!operatorStack.empty())
        {
            compute(operandStack, operatorStack);
        }
        ans = operandStack.top();
        return ans;
    }
};
int main(int argc, char const *argv[])
{
    string s = "1+2*5/3+6/4*2";
    Solution s2;
    cout << s2.calculate(s) << endl;
    return 0;
}
